package com.sillyhat.jbpm.exemple;

import com.sillyhat.jbpm.utils.JunitTestSupport;
import com.sillyhat.studylibrary.jbpm.service.TestService;
import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.File;
import java.util.zip.ZipInputStream;

/**
 * Created by Administrator on 2016-12-10.
 */
public class exempleOne extends JunitTestSupport {

    private Logger logger = LoggerFactory.getLogger(getClass());

//    @Autowired
//    private RepositoryService repositoryService;

    /**
     * 部署流程
     */
    @Test
    public void testDeployProcessXML() {
        ProcessEngine processEngine = Configuration.getProcessEngine();//获取流程引擎
        RepositoryService repositoryService = processEngine.getRepositoryService();//管理流程定义
        repositoryService.createDeployment().addResourceFromClasspath("jbpm/exempleOne.jpdl.xml").deploy();//直接部署流程
    }
    /**
     * 部署流程
     */
    @Test
    public void testDeployProcessFile() {
        ProcessEngine processEngine = Configuration.getProcessEngine();//获取流程引擎
        RepositoryService repositoryService = processEngine.getRepositoryService();//管理流程定义
        repositoryService.createDeployment().addResourceFromFile(new File("F:\\Develop\\workspace\\Work_IdeaWorkspace\\IdeaProjects\\SillyHatStudyLibrary\\SillyHatStudyLibrary-jbpm\\src\\test\\resources\\jbpm\\exempleOne.jpdl.xm"));//直接部署流程
    }

    /**
     * 部署zip流程包（包括xml和png图片）
     */
    @Test
    public void testDeployProcessZIP() {
        ProcessEngine processEngine = Configuration.getProcessEngine();//获取流程引擎
        RepositoryService repositoryService = processEngine.getRepositoryService();//管理流程定义
        ZipInputStream zis = new ZipInputStream(this.getClass().getResourceAsStream("/exempleOne.zip"));
        repositoryService.createDeployment().addResourcesFromZipInputStream(zis).deploy();//将一个zip包进行部署
    }

    /**
     * 启动流程
     */
    @Test
    public void testStartProcess() {
        ProcessEngine processEngine = Configuration.getProcessEngine();//获取流程引擎
        RepositoryService repositoryService = processEngine.getRepositoryService();//管理流程定义
        ZipInputStream zis = new ZipInputStream(this.getClass().getResourceAsStream("/exempleOne.zip"));
        repositoryService.createDeployment().addResourcesFromZipInputStream(zis).deploy();//将一个zip包进行部署
    }

}
